﻿using System;
using System.Windows;
using System.Windows.Forms;
using MessageBox = System.Windows.MessageBox;

namespace IISAutoDeployment
{
    /// <summary>
    /// Mini toolbox window for grabbing secondary node name
    /// </summary>
    public partial class SecondaryNodeInput
    {
        #region Constructors
        public SecondaryNodeInput()
        {
            InitializeComponent();
        }
        #endregion

        #region Event Handlers
        public void CanceledOutside()
        {
            altBackChecked.IsChecked = false;
            NodeName.Text = "";
            BackupFileNameTextBlock.Text = "";
            BackupDrive.Text = "D";
        }

        private void IISNodeButton_OnClick(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrEmpty(NodeName.Text))
            {
                MessageBox.Show("Please enter FQN of secondary node");
                return;
            }
            SecondaryNodeName = NodeName.Text;
            AlternativeBackupLocation = BackupFileNameTextBlock.Text;
            Canceled = false;
            Visibility = Visibility.Hidden;
            IsEnabled = false;
        }

        private void Cancel_OnClick(object sender, RoutedEventArgs e)
        {
            CanceledOutside();
            Canceled = true;
            Visibility = Visibility.Hidden;
            IsEnabled = false;
        }

        private void BackupSelectFileButton_OnClick(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrEmpty(NodeName.Text))
            {
                MessageBox.Show("Please enter FQN of secondary node");
                return;
            }
            if (!altBackChecked.IsChecked.GetValueOrDefault())
            {
                MessageBox.Show("Please check box");
                return;
            }
            if (BackupDrive.Text.Length > 1)
            {
                MessageBox.Show("Please enter only a drive letter in the Set Drive box");
                return;
            }
            var oFd = new FolderBrowserDialog {SelectedPath = @"\\" + NodeName.Text + @"\" + BackupDrive.Text + @"$\"};
            if (oFd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                BackupFileNameTextBlock.Text = oFd.SelectedPath;
            }
        }
        #endregion

        #region Properties
        public string SecondaryNodeName;
        public string AlternativeBackupLocation;
        public bool Canceled = false;
        #endregion
    }
}
